#include"headGram.h"
#include"defines.h"

using namespace std;

element current;

extern char expected;

void ReadFile() {
	
	ifstream in;
	in.open(Stored_File_Name, ios::in);

	while (!in.eof()) {
        in.getline(current.have, Max_Line_Len);
        if (current.have[0] == '\0') break;
        StrDelim(current.have, current);

        if (!G_S()){
            cout << "there has a syntax error: " << expected << " expected;" << endl;
        }
	}

    cout << "program exit with no syntax error" << endl;
}

void StrDelim(std::string input,element& ele) {

    input = input.substr(1, input.length() - 2);
    
    std::string token;
    int number;
    std::istringstream ss(input);

    if (std::getline(ss, token, ',')) {
        strcpy(ele.have, token.erase(0, token.find_first_not_of(" \t\n")).erase(token.find_last_not_of(" \t\n") + 1).c_str());

        if (ss >> number) {
            ele.belong = number;
        }
    }
}

